package com.ruoyi.web.controller.dmpcomponent;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.dmpcomponent.domain.DmpComponentConfig;
import com.ruoyi.dmpcomponent.service.IDmpComponentConfigService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 通用组件配置Controller
 * 
 * @author MquanZeng
 * @date 2021-12-22
 */
@RestController
@RequestMapping("/dmpcomponent/config")
public class DmpComponentConfigController extends BaseController
{
    @Autowired
    private IDmpComponentConfigService dmpComponentConfigService;

    /**
     * 查询通用组件配置列表
     */
    @PreAuthorize("@ss.hasPermi('dmpcomponent:config:list')")
    @GetMapping("/list")
    public TableDataInfo list(DmpComponentConfig dmpComponentConfig)
    {
        startPage();
        List<DmpComponentConfig> list = dmpComponentConfigService.selectDmpComponentConfigList(dmpComponentConfig);
        return getDataTable(list);
    }

    /**
     * 导出通用组件配置列表
     */
    @PreAuthorize("@ss.hasPermi('dmpcomponent:config:export')")
    @Log(title = "通用组件配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DmpComponentConfig dmpComponentConfig)
    {
        List<DmpComponentConfig> list = dmpComponentConfigService.selectDmpComponentConfigList(dmpComponentConfig);
        ExcelUtil<DmpComponentConfig> util = new ExcelUtil<DmpComponentConfig>(DmpComponentConfig.class);
        util.exportExcel(response, list, "通用组件配置数据");
    }

    /**
     * 获取通用组件配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('dmpcomponent:config:query')")
    @GetMapping(value = "/{compId}")
    public AjaxResult getInfo(@PathVariable("compId") Long compId)
    {
        return AjaxResult.success(dmpComponentConfigService.selectDmpComponentConfigByCompId(compId));
    }

    /**
     * 新增通用组件配置
     */
    @PreAuthorize("@ss.hasPermi('dmpcomponent:config:add')")
    @Log(title = "通用组件配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DmpComponentConfig dmpComponentConfig)
    {
        return toAjax(dmpComponentConfigService.insertDmpComponentConfig(dmpComponentConfig));
    }

    /**
     * 修改通用组件配置
     */
    @PreAuthorize("@ss.hasPermi('dmpcomponent:config:edit')")
    @Log(title = "通用组件配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DmpComponentConfig dmpComponentConfig)
    {
        return toAjax(dmpComponentConfigService.updateDmpComponentConfig(dmpComponentConfig));
    }

    /**
     * 删除通用组件配置
     */
    @PreAuthorize("@ss.hasPermi('dmpcomponent:config:remove')")
    @Log(title = "通用组件配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{compIds}")
    public AjaxResult remove(@PathVariable Long[] compIds)
    {
        return toAjax(dmpComponentConfigService.deleteDmpComponentConfigByCompIds(compIds));
    }

    /**
     * 获取调度系统下拉项
     */
    @GetMapping("/selectDCCompList")
    public AjaxResult selectDCCompList()
    {
        return AjaxResult.success(dmpComponentConfigService.getDCCompOptions());
    }
}
